package com.cpx.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Auther: PanBin
 * @Date: 2018-9-6 09:44
 * @Description: Swagger2配置类
 * @Version: 1.0
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

    public static final String SWAGGER_SCAN_BASE_PACKAGE = "com.cpx.controller";
    public static final String VERSION = "1.0.0";

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))//api接口包扫描路径
                .paths(PathSelectors.any())//可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
                //.ignoredParameterTypes(ReplenishOrder.class);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("诚品鲜冷超的接口文档")//设置文档的标题
                .description("PanBin")//API 描述
                .version(VERSION)//设置文档的版本信息
                .contact(new Contact("PanBin", "", "764989742@qq.com"))//创建人
                //.termsOfServiceUrl("www.abc.com")//设置文档的License信息
                .build();
    }
}
